﻿using Microsoft.Extensions.DependencyInjection;
using PetaPoco;
using PmSoft;
using PmSoft.ApplicationContext;
using PmSoft.DBContext;
using PmSoft.Repositories;
using PmSoft.Utilities;

namespace Modules.Project.Repositories
{
    [UseDI(ServiceLifetime.Scoped)]
    public class ProjectGuaranteeAccountRepository : Repository<ProjectGuaranteeAccount, DefaultDbContext>
    {
        public ProjectGuaranteeAccountRepository(DefaultDbContext dbContext, IApplicationContext applicationContext) : base(dbContext, applicationContext)
        {
        }

        /// <summary>
        /// author:hzj date:2023/12/22 describe:分页获取保证金账户
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IPagedList<ProjectGuaranteeAccount> GetProjectGuaranteeAccounts(ProjectGuaranteeAccountQuery query, int pageIndex, int pageSize)
        {
            Sql sql = Sql.Builder;
            sql.Select("id")
                .From("project_guarantee_account");
            if (!string.IsNullOrEmpty(query.Keywords))
                sql.Where("(name Like @0 or code Like @0 )", "%" + StringUtility.StripSQLInjection(query.Keywords) + "%");
            if (query.Type.HasValue) sql.Where("type = @0 ", query.Type);
            sql.OrderBy("create_time DESC");
            return GetPagingEntities(pageSize, pageIndex, sql);
        }
    }
}